using System.Windows.Forms;
using BasecampRestAPI;
using BasecampUI;
using NUnit.Framework;
using TestBasecampRestAPI.TestMoveToDoList;

namespace TestBasecampRestAPI.TestBasecampUI
{
	[TestFixture]
	public class TestCredentialsMainFormMediator
	{
		[Test]
		public void Construct()
		{
			FakeCredentialsMainForm form = FakeCredentialsMainForm.GetInstance();
			CredentialsMainFormMediator mediator = CredentialsMainFormMediator.GetInstance(form);
			Assert.IsNotNull(mediator);
		}

		[Test]
		public void GetBaseCampCancelCredentials()
		{
			FakeCredentialsForm form = FakeCredentialsForm.GetInstance();
			form.ShowDialogFakeResult = DialogResult.Cancel;
			FakeCredentialsMainForm mainForm = FakeCredentialsMainForm.GetInstance();
			mainForm.CredentialsFormGetFakeResult = form;
			CredentialsMainFormMediator mediator = CredentialsMainFormMediator.GetInstance(mainForm);
			IBaseCamp camp;
			bool result = mediator.GetBaseCampFromCredentials(out camp);
			Assert.IsFalse(result);
			Assert.IsNull(camp);
			Assert.IsTrue(mainForm.CredentialsFormGetCalled);
			Assert.IsTrue(form.ShowDialogCalled);
			Assert.IsTrue(mainForm.CloseCalled);
			Assert.IsFalse(form.ServiceGetCalled);
			Assert.IsFalse(mainForm.GetBaseCampCalled);
		}

		[Test]
		public void GetBaseCampAcceptCredentials()
		{
			FakeCredentialsForm form = FakeCredentialsForm.GetInstance();
			form.ShowDialogFakeResult = DialogResult.OK;
			FakeCredentialsMainForm mainForm = FakeCredentialsMainForm.GetInstance();
			mainForm.CredentialsFormGetFakeResult = form;
			FakeRestWebService service = FakeRestWebService.GetInstance();
			form.ServiceGetFakeResult = service;
			CredentialsMainFormMediator mediator = CredentialsMainFormMediator.GetInstance(mainForm);
			IBaseCamp camp;
			bool result = mediator.GetBaseCampFromCredentials(out camp);
			Assert.IsTrue(result);
			Assert.IsNull(camp);
			Assert.IsTrue(mainForm.CredentialsFormGetCalled);
			Assert.IsTrue(form.ShowDialogCalled);
			Assert.IsFalse(mainForm.CloseCalled);
			Assert.IsTrue(form.ServiceGetCalled);
			Assert.IsTrue(mainForm.GetBaseCampCalled);
		}
	}
}